//
//  FoundListCell.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/25.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "FoundListCell.h"

@interface FoundListCell ()

@property (nonatomic, strong) UIImageView *bgView;
@property (nonatomic, strong) UILabel *noteLabel1;
@property (nonatomic, strong) UILabel *noteLabel2;
@property (nonatomic, strong) UILabel *noteLabel3;
@property (nonatomic, strong) UILabel *noteLabel4;

@property (nonatomic, strong) UIImageView *headView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *numLabel;
@property (nonatomic, strong) UILabel *noteLabel;
@property (nonatomic, strong) UIButton *concernBtn;

@end

@implementation FoundListCell

+ (FoundListCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"FoundListCell";
    FoundListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[FoundListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = TABLEVIEW_BACKGROUNDCOLOR;
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    UIView *shadowBg = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(19), ScreenX375(12), (SCREEN_WIDTH - ScreenX375(38)), ScreenX375(407))];
    shadowBg.backgroundColor = [UIColor whiteColor];
    shadowBg.layer.cornerRadius = ScreenX375(8);
    shadowBg.layer.shadowColor = RGBACOLOR(0, 0, 0, 0.11).CGColor;
    shadowBg.layer.shadowOffset = CGSizeMake(0, 4);
    shadowBg.layer.shadowOpacity = 1;
    shadowBg.layer.shadowRadius = 12;
    [self addSubview:shadowBg];
    
    UIView *allBg = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(19), ScreenX375(12), (SCREEN_WIDTH - ScreenX375(38)), ScreenX375(407))];
    allBg.backgroundColor = [UIColor whiteColor];
    allBg.layer.cornerRadius = ScreenX375(8);
    allBg.clipsToBounds = YES;
    [self addSubview:allBg];
    
    self.bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - ScreenX375(38), ScreenX375(337))];
    self.bgView.contentMode = UIViewContentModeScaleAspectFill;
    self.bgView.clipsToBounds = YES;
    [allBg addSubview:self.bgView];
    
    self.noteLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(16), ScreenX375(92), ScreenX375(36))];
    self.noteLabel1.backgroundColor = REXADECIMALCOLOR(@"#ffd100");
    self.noteLabel1.layer.cornerRadius = ScreenX375(4);
    self.noteLabel1.alpha = 0.9;
    self.noteLabel1.textAlignment = NSTextAlignmentCenter;
    self.noteLabel1.textColor = [UIColor whiteColor];
    self.noteLabel1.font = KBlodfont(16);
    self.noteLabel1.clipsToBounds = YES;
    [allBg addSubview:self.noteLabel1];
    
    self.noteLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(62), ScreenX375(70), ScreenX375(24))];
    self.noteLabel2.backgroundColor = RGBACOLOR(0, 0, 0, 0.6);
    self.noteLabel2.layer.cornerRadius = ScreenX375(4);
    self.noteLabel2.alpha = 0.9;
    self.noteLabel2.textAlignment = NSTextAlignmentCenter;
    self.noteLabel2.textColor = [UIColor whiteColor];
    self.noteLabel2.font = KBlodfont(11);
    self.noteLabel2.clipsToBounds = YES;
    [allBg addSubview:self.noteLabel2];
    
    self.noteLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(96), ScreenX375(70), ScreenX375(24))];
    self.noteLabel3.backgroundColor = RGBACOLOR(0, 0, 0, 0.6);
    self.noteLabel3.layer.cornerRadius = ScreenX375(4);
    self.noteLabel3.alpha = 0.9;
    self.noteLabel3.textAlignment = NSTextAlignmentCenter;
    self.noteLabel3.textColor = [UIColor whiteColor];
    self.noteLabel3.font = KBlodfont(11);
    self.noteLabel3.clipsToBounds = YES;
    [allBg addSubview:self.noteLabel3];
    
    self.noteLabel4 = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(130), ScreenX375(93), ScreenX375(24))];
    self.noteLabel4.backgroundColor = RGBACOLOR(0, 0, 0, 0.6);
    self.noteLabel4.layer.cornerRadius = ScreenX375(4);
    self.noteLabel4.alpha = 0.9;
    self.noteLabel4.textAlignment = NSTextAlignmentCenter;
    self.noteLabel4.textColor = [UIColor whiteColor];
    self.noteLabel4.font = KBlodfont(11);
    self.noteLabel4.clipsToBounds = YES;
    [allBg addSubview:self.noteLabel4];
    
    self.headView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(353), ScreenX375(38), ScreenX375(38))];
    self.headView.clipsToBounds = YES;
    self.headView.layer.cornerRadius = ScreenX375(19);
    [allBg addSubview:self.headView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(65), ScreenX375(355), ScreenX375(150), ScreenX375(15))];
    self.nameLabel.textColor = FONTCOLOR_BLACK;
    self.nameLabel.font = KBlodfont(14);
    [allBg addSubview:self.nameLabel];
    
    self.numLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(122), ScreenX375(357), ScreenX375(150), ScreenX375(13))];
    self.numLabel.textColor = REXADECIMALCOLOR(@"#888888");
    self.numLabel.font = Kfont(11);
    [allBg addSubview:self.numLabel];
    
    self.noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(64), ScreenX375(375), ScreenX375(200), ScreenX375(15))];
    self.noteLabel.textColor = REXADECIMALCOLOR(@"#ababab");
    self.noteLabel.font = Kfont(12);
    [allBg addSubview:self.noteLabel];
    
    self.concernBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(260), ScreenX375(355), ScreenX375(66), ScreenX375(26))];
    [self.concernBtn setImage:ImageWithName(@"添加关注") forState:UIControlStateNormal];
    [self.concernBtn setTitle:@" 关注" forState:UIControlStateNormal];
    self.concernBtn.titleLabel.font = Kfont(14);
    [self.concernBtn setTitleColor:REXADECIMALCOLOR(@"#ff2469") forState:UIControlStateNormal];
    self.concernBtn.layer.cornerRadius = ScreenX375(13);
    self.concernBtn.layer.borderWidth = 1;
    self.concernBtn.layer.borderColor = REXADECIMALCOLOR(@"#eaeaea").CGColor;
    [self.concernBtn addTarget:self action:@selector(concernAction) forControlEvents:UIControlEventTouchUpInside];
    [allBg addSubview:self.concernBtn];
}

- (void)setFoundModel:(FoundModel *)foundModel {
    [self.bgView sd_setImageWithURL:[NSURL URLWithString:foundModel.pic] placeholderImage:nil options:SDWebImageRetryFailed];
    
    CGFloat width = kGetStringWidth(foundModel.title, CGSizeMake(ScreenX375(200), ScreenX375(36)), KBlodfont(16));
    self.noteLabel1.text = foundModel.title;
    self.noteLabel1.frame = CGRectMake(ScreenX375(16), ScreenX375(16), width + ScreenX375(28), ScreenX375(36));
    
    if (foundModel.titleOne.length == 0) {
        self.noteLabel2.hidden = YES;
    }else {
        self.noteLabel2.hidden = NO;
        
        CGFloat width = kGetStringWidth(foundModel.titleOne, CGSizeMake(ScreenX375(200), ScreenX375(24)), KBlodfont(11));
        self.noteLabel2.text = foundModel.titleOne;
        self.noteLabel2.frame = CGRectMake(ScreenX375(16), ScreenX375(62), width + ScreenX375(28), ScreenX375(24));
    }
    
    if (foundModel.titleTwo.length == 0) {
        self.noteLabel3.hidden = YES;
    }else {
        self.noteLabel3.hidden = NO;
        
        CGFloat width = kGetStringWidth(foundModel.titleTwo, CGSizeMake(ScreenX375(200), ScreenX375(24)), KBlodfont(11));
        self.noteLabel3.text = foundModel.titleTwo;
        self.noteLabel3.frame = CGRectMake(ScreenX375(16), ScreenX375(96), width + ScreenX375(28), ScreenX375(24));
    }
    
    if (foundModel.titleThree.length == 0) {
        self.noteLabel4.hidden = YES;
    }else {
        self.noteLabel4.hidden = NO;
        
        CGFloat width = kGetStringWidth(foundModel.titleThree, CGSizeMake(ScreenX375(200), ScreenX375(24)), KBlodfont(11));
        self.noteLabel4.text = foundModel.titleThree;
        self.noteLabel4.frame = CGRectMake(ScreenX375(16), ScreenX375(130), width + ScreenX375(28), ScreenX375(24));
    }
    self.nameLabel.text = foundModel.userName;
    self.numLabel.text = [NSString stringWithFormat:@"%@个作品",foundModel.proNum];
    CGFloat nameWidth = kGetStringWidth(foundModel.userName, CGSizeMake(ScreenX375(150), ScreenX375(15)), KBlodfont(14));
    self.numLabel.frame = CGRectMake(ScreenX375(68) + nameWidth, ScreenX375(357), ScreenX375(150), ScreenX375(13));
    self.noteLabel.text = foundModel.userIntro;
    [self.headView sd_setImageWithURL:[NSURL URLWithString:foundModel.userPic] placeholderImage:nil options:SDWebImageRetryFailed];
    
    if ([foundModel.isFollow integerValue]) {
        [self.concernBtn setTitle:@"已关注" forState:UIControlStateNormal];
        [self.concernBtn setTitleColor:REXADECIMALCOLOR(@"#212121") forState:UIControlStateNormal];
        [self.concernBtn setImage:nil forState:UIControlStateNormal];
    }else {
        [self.concernBtn setTitle:@" 关注" forState:UIControlStateNormal];
        [self.concernBtn setTitleColor:REXADECIMALCOLOR(@"#ff2469") forState:UIControlStateNormal];
        [self.concernBtn setImage:ImageWithName(@"添加关注") forState:UIControlStateNormal];
    }
}

- (void)setPosterInfoModel:(PostersInfoModel *)posterInfoModel {
    [self.bgView sd_setImageWithURL:[NSURL URLWithString:posterInfoModel.pic] placeholderImage:nil options:SDWebImageRetryFailed];
    if ([posterInfoModel.oneTitle class] != [NSNull class]) {
        self.noteLabel1.text = posterInfoModel.oneTitle;
    }
    if ([posterInfoModel.twoTitle1 class] != [NSNull class]) {
        self.noteLabel2.text = posterInfoModel.twoTitle1;
    }
    if ([posterInfoModel.twoTitle2 class] != [NSNull class]) {
        self.noteLabel3.text = posterInfoModel.twoTitle2;
    }
    if ([posterInfoModel.twoTitle3 class] != [NSNull class]) {
        self.noteLabel4.text = posterInfoModel.twoTitle3;
    }
}

- (void)setPostersModel:(PostersModel *)postersModel {
    if ([postersModel.pic class] != [NSNull class]) {
        [self.headView sd_setImageWithURL:[NSURL URLWithString:postersModel.pic] placeholderImage:nil options:SDWebImageRetryFailed];
    }
    self.nameLabel.text = postersModel.nickName;
    self.noteLabel.text = postersModel.intro;
}

- (void)concernAction {
    if (_concernClick) {
        _concernClick();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@implementation FoundModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id"
                                                                  }];
}


@end

@implementation PostersModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id"
                                                                  }];
}


@end


@implementation PostersInfoModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id"
                                                                  }];
}


@end
